package etnorservice.etnor_service.controller;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2024/11/30/11:33
 **/

import etnorservice.etnor_service.domain.po.Like;
import etnorservice.etnor_service.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/likes")
public class LikeController {

    @Autowired
    private LikeService likeService;

    @PostMapping
    public ResponseEntity<Void> addLike(@RequestBody Like like) {
        likeService.addLike(like);
        return ResponseEntity.ok().build();
    }

    @DeleteMapping
    public ResponseEntity<Void> removeLike(@RequestParam Long userId,
                                           @RequestParam Long targetId,
                                           @RequestParam Integer targetType) {
        likeService.removeLike(userId, targetId, targetType);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/check")
    public ResponseEntity<Boolean> checkUserLike(@RequestParam Long userId,
                                                 @RequestParam Long targetId,
                                                 @RequestParam Integer targetType) {
        return ResponseEntity.ok(likeService.hasUserLiked(userId, targetId, targetType));
    }

    @GetMapping("/count")
    public ResponseEntity<Integer> getLikeCount(@RequestParam Long targetId,
                                                @RequestParam Integer targetType) {
        return ResponseEntity.ok(likeService.getLikeCount(targetId, targetType));
    }
}
